/*
 * Copyright 2017 JessYan
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *      http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.kmproject.haifu.mvp.model.api.service;

import android.support.annotation.NonNull;
import android.support.annotation.Nullable;

import com.kmproject.haifu.mvp.model.api.Api;
import com.kmproject.haifu.mvp.model.entity.ResultBean;
import com.kmproject.haifu.mvp.model.entity.User;
import com.kmproject.haifu.mvp.model.entity.beans.CommentListBean;
import com.kmproject.haifu.mvp.model.entity.beans.GooglePlaceInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.GooglePlaceInfoTextSearchBean;
import com.kmproject.haifu.mvp.model.entity.beans.HomeBannerBean;
import com.kmproject.haifu.mvp.model.entity.beans.HomeNewsBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseInfoTitleBean;
import com.kmproject.haifu.mvp.model.entity.beans.HousePayWayBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowBean;
import com.kmproject.haifu.mvp.model.entity.beans.HouseRentListShowInfoBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyCommonPublishCountBean;
import com.kmproject.haifu.mvp.model.entity.beans.MyStoryBean;
import com.kmproject.haifu.mvp.model.entity.beans.QueryAreaByLtLotBean;
import com.kmproject.haifu.mvp.model.entity.beans.RentHouseViewHistoryBean;
import com.kmproject.haifu.mvp.model.entity.beans.RentSeekingDetail;
import com.kmproject.haifu.mvp.model.entity.beans.SeletCityBean;
import com.kmproject.haifu.mvp.model.entity.beans.StatisticsBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserAttentionBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserHomePageBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserLoginBean;
import com.kmproject.haifu.mvp.model.entity.beans.UserSfBean;
import com.kmproject.haifu.mvp.model.entity.beans.VerificationBean;
import com.kmproject.haifu.mvp.model.entity.beans.ViewStoreInfoBean;

import java.util.List;
import java.util.Map;

import io.reactivex.Observable;
import okhttp3.RequestBody;
import retrofit2.Retrofit;
import retrofit2.http.Body;
import retrofit2.http.Field;
import retrofit2.http.FieldMap;
import retrofit2.http.FormUrlEncoded;
import retrofit2.http.GET;
import retrofit2.http.Headers;
import retrofit2.http.POST;
import retrofit2.http.Query;
import retrofit2.http.Url;

//import okhttp3.MultipartBody;

/**
 * ================================================
 * 展示 {@link Retrofit#create(Class)} 中需要传入的 ApiService 的使用方式
 * 存放关于用户的一些 API
 * <p>
 * Created by JessYan on 08/05/2016 12:05
 * <a href="mailto:jess.yan.effort@gmail.com">Contact me</a>
 * <a href="https://github.com/JessYanCoding">Follow me</a>
 * ================================================
 */
public interface UserService {
    String HEADER_API_VERSION = "Accept: application/vnd.github.v3+json";

    @Headers({HEADER_API_VERSION})
    @GET("/users")
    Observable<List<User>> getUsers(@Query("since") int lastIdQueried, @Query("per_page") int perPage);

    @FormUrlEncoded
    @POST("/server/user/add")
    Observable<ResultBean<User>> addUser(@Field("user") String user);


    /**
     * 上传头像
     */
//    @Multipart
//    @POST("/server/user/upload")
//    Observable<String> uploadMemberIcon( @Part MultipartBody.Part multipartFile);

    //======================================================================================================
    //登录
    @FormUrlEncoded
    @POST("/app/login/token")
    Observable<ResultBean<UserLoginBean>> userLogin(@Field("username") String username, @Field("password") String password);

    //注册获取验证码
    @FormUrlEncoded
    @POST("/app/send/message")
    Observable<ResultBean<VerificationBean>> queryVerification(@Field("phoneNum") String phoneNum, @Field("sessionId") String sessionId, @Field("appKey") String appKey);

    //注册
    @FormUrlEncoded
    @POST("/app/user/register")
    Observable<ResultBean> userRegist(@Field("password") String password, @Field("userType") String userType, @Field("mobile") String mobile
            , @Field("identifyCode") String identifyCode);


    //忘记密码获取验证码
    @FormUrlEncoded
    @POST("/app/forgotPwd/send/message")
    Observable<ResultBean<VerificationBean>> queryVerificationForForgetPwd(@Field("phoneNum") String phoneNum, @Field("sessionId") String sessionId, @Field("appKey") String appKey);

    //重置密码
    @FormUrlEncoded
    @POST("/app/user/resetPassword")
    Observable<ResultBean> resetPwd(@Field("password") String password, @Field("mobile") String mobile, @Field("identifyCode") String identifyCode);


    //获取用户信息
    @POST("/app/getUserInfo")
    Observable<ResultBean<UserBean>> qurUserInfo();

    //设置个性签名
    @FormUrlEncoded
    @POST("/app/updateUserDesc")
    Observable<ResultBean> updateUserDesc(@Field("userDesc") String userDesc);

    //设置昵称
    @FormUrlEncoded
    @POST("/app/updateUserNickName")
    Observable<ResultBean> updateUserNickName(@Field("nickName") String nickName);

    //修改密码
    @FormUrlEncoded
    @POST("/app/updPassword")
    Observable<ResultBean> updPassword(@Field("oldPassword") String oldPassword, @Field("newPassword") String newPassword);

    //设置头像
    @FormUrlEncoded
    @POST("/app/updHeadPortrait")
    Observable<ResultBean> updHeadPortrait(@Field("avatar") String avatar);


    //设置性别
    @FormUrlEncoded
    @POST("/app/updUserSex")
    Observable<ResultBean> updUserSex(@Field("userSex") String userSex);


    //设置昵称
    @FormUrlEncoded
    @POST("/app/logout/token")
    Observable<ResultBean> logout(@Field("token") String token);


    //获取区域
    @GET()
    Observable<ResultBean<List<HousePayWayBean>>> getAreaTree(@Url String url, @Query("value") String value, @Query("category") String category);

    //获取区域
    @FormUrlEncoded
    @POST()
    Observable<ResultBean<List<HousePayWayBean>>> dictList(@Url String url, @Field("value") String value, @Field("category") String category);


    //手机好嘛验证获取验证码
    @FormUrlEncoded
    @POST("/app/send/sendHouseVerifyCode")
    Observable<ResultBean<VerificationBean>> sendHouseVerifyCode(@Field("phoneNum") String phoneNum);

    //验证手机号码验证码
    @FormUrlEncoded
    @POST("/app/houseCheckIsCorrectCode")
    Observable<ResultBean> houseCheckIsCorrectCode(@Field("phoneNum") String phoneNum, @Field("identifyCode") String identifyCode);

    @FormUrlEncoded
    @POST("/app/addHouseRent")
    Observable<ResultBean> addHouseRent(@Field("houseName") String houseName, @Field("rentType") String rentType, @Field("houseArea") String houseArea, @Field("log") String lgt,
                                        @Field("lat") String lat, @Field("acreage") String acreage, @Field("floor") String floor, @Field("totalFloor") String totalFloor,
                                        @Field("monthRent") double monthRent, @Field("dayRent") double dayRent, @Field("cashPledge") double cashPledge, @Field("landlord") String landlord,
                                        @Field("landlordGender") String landlordGender, @Field("landlordType") String landlordType, @Field("landlordMobile") String landlordMobile, @Field("detail") String detail,
                                        @Field("roomCount") String roomCount, @Field("drawingCount") String drawingCount, @Field("toiletCount") String toiletCount, @Field("isVerify") String isVerify,
                                        @Field("rentRoom") String rentRoom, @Field("houseImage") String houseImage, @Field("houseRentDetail") String houseRentDetail);



    //获取租房付款方式
    @FormUrlEncoded
    @POST()
    Observable<ResultBean<List<HouseInfoTitleBean.HouseInfoConfiguration>>> dictListToConfiguration(@Url String url, @Field("value") String value);

    //获取用户身份
    @POST("/app/getUserShop")
    Observable<ResultBean<UserSfBean>> getUserShop();


    //租房展示列表查询
    @FormUrlEncoded
    @POST("/app/getHouseRentList")
    Observable<ResultBean<List<HouseRentListShowBean>>> getHouseRentList(@FieldMap Map<String, Object> params);


    //获取详情
    @GET()
    Observable<ResultBean<HouseRentListShowInfoBean>> viewHouseRent(@Url String url);


    //添加关注
    @POST()
    Observable<ResultBean> add(@Url String url);

    //取消关注
    @POST()
    Observable<ResultBean> canl(@Url String url);


    //删除租房信息
    @FormUrlEncoded
    @POST()
    Observable<ResultBean> delRentHouse(@Url String url, @Field("houseRentIds") String houseRentIds);


    //举报添加
    @FormUrlEncoded
    @POST("/app/userReport/addUserReport")
    Observable<ResultBean> addReport(@FieldMap Map<String, Object> params);


    //租房收藏、发布、浏览列表
//    @Headers("Content-Type: application/json")
//    @FormUrlEncoded
    @GET()
    Observable<ResultBean<List<HouseRentListShowInfoBean>>> getMeList(@Url String url, @Query("limit") String limit, @Query("page") String page, @Query("userId") String userId);

    //获取地址选区列表
//    @GET("/app/getIndexHouseArea")
    @GET("/app/baseArea/getIndexArea")
    Observable<ResultBean<List<SeletCityBean>>> getIndexHouseArea();

    //google 关键子搜索
//    https//maps.googleapis.com/maps/api/place/textsearch/json?key=AIzaSyCLZbTQd4VYHukMl_EzYNZPJSOWHWpE4hM&query=${this.keyword}
//    @Headers({"Domain-Name: douban"}) // 加上 Domain-Name header
    @FormUrlEncoded
    @POST()
    Observable<String> searchAddressForGoogle(@Url String url, @Field("key") String key, @Field("query") String query);

    /**
     * 关键字检索位置信息
     *
     * @param url
     * @param key
     * @param location
     * @param radius
     * @param language zh-CN：简体中文；en：英文
     * @return
     */
    @GET()
    Observable<GooglePlaceInfoBean> nearbySearchRequest(@Url String url, @Query("key") String key, @Query("location") String location, @Nullable @Query("pagetoken") String pagetoken, @Query("radius") int radius, @Query("language") String language);

    /**
     * 关键字检索位置信息
     *
     * @param url
     * @param key
     * @param keyword
     * @param location
     * @param radius
     * @param language zh-CN：简体中文；en：英文
     * @param region   cn：中国地区；hk：香港；mo：澳门；tw：台湾；ph：菲律宾。{可以使用 region 参数将 Google Maps Geocoding API 设置为返回偏向于特定地区的结果。该参数带有指定地区偏向的 ccTLD（国家代码顶级域）自变量。大多数 ccTLD 代码与 ISO 3166-1 代码相同，但有一些明显的例外。例如，英国的国家代码顶级域名为“uk”(.co.uk)，而其 ISO 3166-1 代码却是“gb”（专指“大不列颠及北爱尔兰联合王国”这一实体）。
     *                 <p>
     *                 地理编码结果可以偏向于正式推出了主要 Google Maps 应用的每个区域。请注意，偏向只是倾向于使用某个特定区域的结果；如果在此区域以外存在更相关的结果，也可能会将这些结果包括在内。}
     * @return
     */
    @GET()
    Observable<GooglePlaceInfoTextSearchBean> keywordSearchRequest(@Url String url, @Query("key") String key, @Query("query") String keyword, @Nullable @Query("location") String location, @Nullable @Query("pagetoken") String pagetoken,
                                                                   @Query("radius") int radius, @Query("language") String language, @NonNull @Query("region") String region, @Nullable @Query("type") String type);

    /**
     * 根据经纬度查询区域
     *
     * @return
     */
    @GET("/app/baseArea/getLocationByLngLat")
    Observable<ResultBean<QueryAreaByLtLotBean>> getLocationByLngLat(@Query("lat") String lat, @Query("lgt") String lgt);

    /**
     * 首页banner图
     *
     * @return
     */
    @GET("/app/getHomeBannerList/query")
    Observable<ResultBean<List<HomeBannerBean>>> getHomeBanner();

    /**
     * 首页资讯列表
     *
     * @return
     */
    @POST("/app/headlineNews/listHeadlineNews")
    Observable<ResultBean<List<HomeNewsBean>>> getHomeNews(@Body RequestBody body);

    /**
     * 首页资讯详情
     *
     * @return
     */
    @GET()
    Observable<ResultBean<HomeNewsBean>> getHomeNewsDetail(@Url String url);

    /**
     * 添加评论
     *
     * @return
     */
    @POST(Api.USER_COMMENT_ADD_COMMENT)
    Observable<ResultBean> addComment(@Body RequestBody body);

    /**
     * 取消赞
     *
     * @return
     */
    @POST()
    Observable<ResultBean> cancelComment(@Url String url);

    /**
     * icon_un_like
     *
     * @return
     */
    @POST()
    Observable<ResultBean> likeComment(@Url String url);

    /**
     * 查询评论列表
     *
     * @return
     */
    @POST(Api.USER_COMMENT_LIST_COMMENT)
    Observable<ResultBean<List<CommentListBean>>> getCommentList(@Body RequestBody body);

    /**
     * 删除评论
     *
     * @return
     */
    @POST()
    Observable<ResultBean> deleteComment(@Url String url);

    //===============================================================application/json=============
    //    查询当前用户的租房列表(包括发布、浏览、收藏) 查询类型:0-发布,1-收藏,2-浏览记录
    @POST("/app/listHouseRent/currentUser")
    Observable<ResultBean<List<HouseRentListShowInfoBean>>> queryCurrentUserRentHouseList(@Body RequestBody body);

    //删除当前用户的租房列表(包括发布、浏览、收藏)删除类型:0-发布,1-收藏,2-浏览记录
    @POST("/app/removeHouseRent/currentUser")
    Observable<ResultBean> removeCurrentUserRentHouseList(@Body RequestBody body);

    //查询当前房东下的浏览记录
    @GET("/app/listHouseRent/viewRecord/current")
    Observable<ResultBean<List<RentHouseViewHistoryBean>>> viewRecord(@Query("limit") String limit, @Query("page") String page);

    //根据id获取用户发布租房
    @GET("/app/getHouseRentByUser")
    Observable<ResultBean<List<HouseRentListShowInfoBean>>> getHouseRentByUser(@Query("limit") String limit, @Query("page") String page, @Query("userId") String userId, @Nullable @Query("houseCategory") String houseCategory);

    //点击下一步验证验证码是否正确
    @FormUrlEncoded
    @POST("/app/user/registerNext")
    Observable<ResultBean> registerNext(@Field("mobile") String mobile, @Field("identifyCode") String identifyCode);

    //根据id获取用户发布租房
    @GET(Api.MEMBER_LEVEL_USER_HOME_PAGE)
    Observable<ResultBean<UserHomePageBean>> getUserHomePageInfo(@Query("userId") String userId);

    //我个人中心数量统计
    @GET()
    Observable<ResultBean<MyCommonPublishCountBean>> myCommonPublishCount(@Url String url);

    //浏览店铺信息
    @GET(Api.USER_STORE_VIEW_STORE_INFO)
    Observable<ResultBean<ViewStoreInfoBean>> viewStoreInfo(@Query("storeId") String storeId, @Query("deviceId") String deviceId);

    //获取租房发布类型
    @GET("/app/dictListAndChild")
    Observable<ResultBean<List<HousePayWayBean>>> dictListForPublishType(@Query("value") String value);


    //获取租房发布类型(不分组)
    @FormUrlEncoded
    @POST("/app/dictList")
    Observable<ResultBean<List<HousePayWayBean>>> dictListForSeekingPublishType(@Field("value") String value);

    //获取租房发布类型
    @POST("/app/userStore/listStore/estate/currentUser")
    Observable<ResultBean<List<MyStoryBean.ResultBean>>> querySelectStory(@Body RequestBody body);

    @POST(Api.HOUSE_RENT_SEEKING_ADD)
    Observable<ResultBean<RentSeekingDetail>> releaseRentSeeking(@Body RequestBody body);

    //根据id查询发布求租详情
    @GET(Api.HOUSE_RENT_SEEKING_DETAIL)
    Observable<ResultBean<RentSeekingDetail>> getHouseRentSeekingDetail4Id(@Query("seekingId") String seekingId);

    //删除求租
    @POST(Api.HOUSE_RENT_SEEKING_DELETE)
    Observable<ResultBean> deleteRentSeeking(@Body RequestBody body);

    //更新求租信息
    @POST()
    Observable<ResultBean<RentSeekingDetail>> updateRentSeeking(@Url String url, @Body RequestBody body);

    //根据店铺查询租房列表
    @FormUrlEncoded
    @POST()
    Observable<ResultBean<List<HouseRentListShowInfoBean>>> listHouseRent4Store(@Url String url, @Query("limit") String limit, @Query("page") String page, @Field("storeId") String storeId, @Body RequestBody body);

    @POST(Api.HOUSE_RENT_SEEKING_LIST_QUERY)
    Observable<ResultBean<List<RentSeekingDetail>>> getHouseRentSeekingList(@Body RequestBody body);

    @POST(Api.HOUSE_RENT_SEEKING_BY_USER_QUERY)
    Observable<ResultBean<List<RentSeekingDetail>>> houseRentSeekingByUser(@Body RequestBody body);

    //    @POST(Api.ADD_HOUSE_RENT_SEEKING_COLLECTION)
    @POST()
    Observable<ResultBean> addHouseRentSeekingCollection(@Url String url);

    @POST(Api.CANCEL_HOUSE_RENT_SEEKING_COLLECTION)
    Observable<ResultBean> cancelHouseRentSeekingCollection(@Body RequestBody body);

    @POST(Api.USER_COLLECTION_SEEKING_QUERY)
    Observable<ResultBean<List<RentSeekingDetail>>> userCollectionSeekingQuery(@Body RequestBody body);

    //字典配置表
    @FormUrlEncoded
    @POST("/app/dictList")
    Observable<ResultBean<List<HousePayWayBean>>> dictList(@Field("value") String value, @Field("category") String category);

    //获取获取关联楼层-发布仓库地方使用
    @GET("/app/getFloorTypeAndFloor")
    Observable<ResultBean<List<HousePayWayBean>>> getFloorTypeAndFloor();

    //获取租房信息查询条件树
    @GET("/app/houseRent/getQueryConditionTree")
    Observable<ResultBean<List<HousePayWayBean>>> getQueryConditionTree(@Query("houseCategory") String houseCategory, @Query("rentType") String rentType);

    //   用户注册发送短信验证码
    @FormUrlEncoded
    @POST("/app/send/message")
    Observable<ResultBean<VerificationBean>> regist_message_new(@FieldMap Map<String, Object> params);

    //用户忘记密码发送短信验证码
    @FormUrlEncoded
    @POST("/app/forgotPwd/send/message")
    Observable<ResultBean<VerificationBean>> forgotPwdMessage_new(@FieldMap Map<String, Object> params);

    //忘记密码下一步
    @FormUrlEncoded
    @POST("/app/user/forgotPwdNext")
    Observable<ResultBean> forgotPwdNext(@FieldMap Map<String, Object> params);

    //请求租房列表改成application/json
    @POST("/app/getHouseRentList")
    Observable<ResultBean<List<HouseRentListShowBean>>> getHouseRentList_mew(@Body RequestBody body);

    //删除租房信息
    @FormUrlEncoded
    @POST("/app/removeHouseRent")
    Observable<ResultBean> removeHouseRent(@Field("rentId") String rentId);

    //下架租房信息
    @FormUrlEncoded
    @POST("/app/lowerShelfHouseRent")
    Observable<ResultBean> lowerShelfHouseRent(@Field("rentId") String rentId, @Field("lowerShelfReason") String lowerShelfReason);

    //查询当前用户的租房列表(包括发布、浏览、收藏) 查询类型:0-发布,1-收藏,2-浏览记录
    @POST("/app/listHouseRent/currentUser")
    Observable<ResultBean<List<HouseRentListShowInfoBean>>> listHouseRentCurrentUser(@Body RequestBody body);

    /*---------关注-------------*/
    @POST(Api.USER_ATTENTION_ADD)
    Observable<ResultBean> userAttentionAdd(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_CANCEL)
    Observable<ResultBean> userAttentionCancel(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_LIST_ATTENTION_STORE_CURRENT_USER)
    Observable<ResultBean<List<UserAttentionBean>>> listAttentionStoreCurrentUser(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_LIST_ATTENTION_STORE_OTHER_USER)
    Observable<ResultBean<List<UserAttentionBean>>> listAttentionStoreOtherUser(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_LIST_ATTENTION_USER_CURRENT_USER)
    Observable<ResultBean<List<UserAttentionBean>>> listAttentionUserCurrentUser(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_LIST_ATTENTION_USER_OTHER_USER)
    Observable<ResultBean<List<UserAttentionBean>>> listAttentionUserOtherUser(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_LIST_USER_ATTENTION_CURRENT_USER_OR_STORE)
    Observable<ResultBean<List<UserAttentionBean>>> listUserAttentionCurrentUserOrStore(@Body RequestBody body);

    @POST(Api.USER_ATTENTION_LIST_USER_ATTENTION_OTHER_USER_OR_OTHER_STORE)
    Observable<ResultBean<List<UserAttentionBean>>> listUserAttentionOtherUserOrStore(@Body RequestBody body);

    //查询当前用户下店铺下的的房源
    @POST("/app/getHouseRentByCurrentStore")
    Observable<ResultBean<List<HouseRentListShowBean>>> getHouseRentByCurrentStore(@Body RequestBody body);


    //我个人中心数量统计
    @GET()
    Observable<ResultBean<StatisticsBean>> myCommonPublishCount_new(@Url String url);

    //编辑租房信息
    @POST("/app/updateHouseRent")
    Observable<ResultBean> updateHouseRent(@Body RequestBody body);
    //发送租房
    @POST("/app/addHouseRent")
    Observable<ResultBean> addHouseRent(@Body RequestBody body);
}
